﻿
using System;
using System.Threading;
using System.ComponentModel;
using System.Diagnostics;

namespace OtherDevice
{
    class L600_Balance : Balance_Base
    {
        Object muxt = new Object();
        public override int Get(ref double pos, bool wait = true)
        {
            try
            {
                lock (muxt)
                {
                    byte[] SendCommand = new byte[8];
                    SendCommand[0] = 0x01;
                    SendCommand[1] = 0x03;
                    SendCommand[2] = 0x06;
                    SendCommand[3] = 0x06;
                    SendCommand[4] = 0x00;
                    SendCommand[5] = 0x02;
                    SendCommand[6] = 0x24;
                    SendCommand[7] = 0x82;
                    byte[] result = SendAndReceiveData(SendCommand, 3000);
                    if(result.Length>0)
                    {
                        double d_Value = 0;
                        if (result[3] == 255)
                            d_Value = (result[6] - 255) + (result[5] - 255) * 256 + (result[4] - 255) * 256 * 256 + (result[3] - 255) * 256 * 256 * 256;
                        else
                            d_Value = result[6] + result[5] * 256 + result[4] * 256 * 256 + result[3] * 256 * 256 * 256;
                        pos = d_Value / 1000;
                        return 0;
                    }
                    else
                    {
                        pos = 0;return -1;
                    }

                }
            }
            catch (Exception ex)
            {
                pos = 0;
                return -1;
            }
            return 0;
        }

        public override int Init(string CommPort, string paramter = "19200,n,8,2")
        {
            int EC;
            try
            {
                EC = InitCom(CommPort, paramter);
                //SetPowerOn();
                //SetZore();
            }
            catch (Exception ex)
            {
                return -1;
            }
            return EC;
        }

        public override void SetZore()
        {
        }

        public override void SetPowerOn()
        {
        }

        public override void SetPowerOff()
        {
        }

    }
}